package com.etong.frame.directive.impl.database;

import java.util.Map;

import com.etong.frame.directive.util.CommonStatus;

public class DatabaseDelete extends DatabaseDirective {

	StringBuilder deleteBuilder;

	public DatabaseDelete(Statement statement) {
		super(statement);
		setNeedFields(false);
	}

	@Override
	public boolean buildConst(Statement op) {

		deleteBuilder = new StringBuilder(100);

		deleteBuilder.append("delete from ").append(
				getStatement().getTable_name());

		String whereExpr = getStatement().getWhere_expr();
		if (null != whereExpr && !whereExpr.isEmpty()) {
			// 创建Select语句变量
			addPlaceholders(createPlaceholders(whereExpr, true));
			deleteBuilder.append(" where ").append(whereExpr);
		}

		logger.info("Build delete:" + getStatement().getName() + "->"
				+ deleteBuilder.toString());
		return true;
	}

	@Override
	protected CommonStatus buildVariable(Map<String, Object> vars) {
		CommonStatus status = new CommonStatus();
		status.setObject(deleteBuilder.toString());
		return status;
	}

	public String getStatementConfig() {
		return deleteBuilder.toString();
	}

}
